package com.winterwar.dao.hibernate;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.winterwar.base.Convention;
import com.winterwar.dao.ConventionDAO;

public class ConventionDAOHibernate extends HibernateDaoSupport implements ConventionDAO{
	
	private Log log = LogFactory.getLog(ConventionDAO.class);
	public Convention get(Integer conID) {
		return (Convention) getHibernateTemplate().get(Convention.class, conID);
	}

	public List getAll() {
		return getHibernateTemplate().find("from Convention order by conName asc");
	}

	public void remove(Integer conID) {
		log.info("ConID passed in is: " + conID);
		Object con = getHibernateTemplate().load(Convention.class, conID);
		log.info("starting delete of object con... : " + ((Convention) con).getConID());
		getHibernateTemplate().delete(con);
		getHibernateTemplate().flush();
	}

	public void save(Convention convention) {
		getHibernateTemplate().saveOrUpdate(convention);
		getHibernateTemplate().flush();
		if(log.isDebugEnabled()){
			log.debug("New Convention ID is : " + convention.getConID());
		}
	}

	public List getCurrentCon() {
		return getHibernateTemplate().find("from Convention where current = true");
	}

}
